package com.example.learnandroiduicontrol;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private RadioGroup radioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        前后端控件绑定
        radioGroup = findViewById(R.id.rgp);
//        单选事件处理，设置选择改变的监听器
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(RadioGroup group,int checkedId){
                switch(checkedId){
                    case R.id.rb1:
                        Toast.makeText(MainActivity.this, "您最喜欢的季节是——春", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.rb2:
                        Toast.makeText(MainActivity.this, "您最喜欢的季节是——夏", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.rb3:
                        Toast.makeText(MainActivity.this, "您最喜欢的季节是——秋", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.rb4:
                        Toast.makeText(MainActivity.this, "您最喜欢的季节是——冬", Toast.LENGTH_SHORT).show();
                        break;
                    default:
                        break;
                }
            }
        });
    }
}